package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.pojo.Student;
import com.qf.service.StudentService;
import com.qf.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by 54110 on 2021/4/16.
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    StudentService studentService;

    /**
     * 路径传参
     * @return
     */
    @RequestMapping("/findAll")
    public BaseResult findAll(@RequestParam("page")Integer page, @RequestParam("limit")Integer size){
        List<Student> all = studentService.findAll(page, size);
        PageInfo<Student> studentPageInfo = new PageInfo<>(all);
        BaseResult baseResult = new BaseResult();
        baseResult.setCode(0);
        baseResult.setMessage("ok");
        baseResult.setData(studentPageInfo.getList());
        baseResult.setCount(studentPageInfo.getTotal());
        return baseResult;
    }

    @RequestMapping("/delById")
    public BaseResult delById(@RequestBody Map map){
    return studentService.delById((Integer)map.get("id"));
    }

    @RequestMapping("/updateById")
    public BaseResult updateById(@RequestBody Student student){
        return studentService.updateById(student);
    }
}
